﻿package 
{
	import cn.antscript.airCMS.data.IGroupBtn;
	import cn.antscript.airCMS.data.ImgsData;
	import cn.antscript.airCMS.data.PageData;
	import cn.antscript.airCMS.data.singleData.AbstractData;
	import cn.antscript.airCMS.data.singleData.ImgData;
	import cn.antscript.airCMS.data.singleData.TextData;
	import cn.antscript.airCMS.data.XMLData;
	import cn.antscript.airCMS.display.component.AbstractItemContainer;
	import cn.antscript.airCMS.display.component.AddPanel;
	import cn.antscript.airCMS.display.component.AlertPanel;
	import cn.antscript.airCMS.display.component.btnbase.AbstractBtn;
	import cn.antscript.airCMS.display.component.btnbase.AbstractIco;
	import cn.antscript.airCMS.display.component.btnbase.FileBtn;
	import cn.antscript.airCMS.display.component.btnbase.IcoBitmapdatas;
	import cn.antscript.airCMS.display.component.btnbase.ImgBtn;
	import cn.antscript.airCMS.display.component.btnbase.TextBtn;
	import cn.antscript.airCMS.display.component.EditPanel;
	import cn.antscript.airCMS.display.component.ProgressPanel;
	import cn.antscript.airCMS.display.component.SurePanel;
	import cn.antscript.airCMS.display.component.TypeContainer;
	import cn.antscript.airCMS.display.component.UserManagerPanel;
	import cn.antscript.airCMS.display.component.WaitBar;
	import cn.antscript.airCMS.display.ImgViewer;
	import cn.antscript.airCMS.display.MusicListener;
	import cn.antscript.model.SqlModel;
	import com.adobe.crypto.MD5;
	import com.bit101.components.Calendar;
	import com.bit101.components.CheckBox;
	import com.bit101.components.InputText;
	import com.bit101.components.Label;
	import com.bit101.components.PushButton;
	import com.bit101.components.RadioButton;
	import com.bit101.components.Text;
	import com.bit101.components.VSlider;
	import com.maclema.mysql.Connection;
	import com.maclema.mysql.events.MySqlErrorEvent;
	import com.maclema.mysql.events.MySqlEvent;
	import com.maclema.mysql.Field;
	import com.maclema.mysql.MySqlToken;
	import com.maclema.mysql.Statement;
	import flash.data.SQLConnection;
	import flash.display.NativeWindow;
	import flash.display.NativeWindowInitOptions;
	import flash.display.NativeWindowSystemChrome;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
    import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.system.System;
    

    public class Main extends Sprite
    {
		
		var conn:Connection;
        
        public function Main()
        {
			//conn = new Connection("localhost", 3306, "antscript", "fjh0fjh", "cmstest");
			//conn.addEventListener(Event.CONNECT, handleConnected);
			//conn.addEventListener(MySqlErrorEvent.SQL_ERROR, onErr);
			//conn.addEventListener(IOErrorEvent.IO_ERROR, onErr);
			//conn.connect();
			
			
			
			System.useCodePage = true;
			//trace(MD5.hash("fjh0fjh"));
			//MusicListener.getInstance().play("rock-guitar.mp3", this);
			
			//var sg:TextData = new TextData("1", "lablehhhhh", "asldkfajsdf", "");
			//EditPanel.getInstance().edit(sg, this);
			
			
			
			//ImgViewer.getInstance().show("1.jpg");
			
			//this.x = 100;
			//this.y = 300;
			
			//new Label(this, 100, 100, "退出");
			//fgg.active = false;
			//fgg.close();
			//fgg.
			
			//var options:NativeWindowInitOptions = new NativeWindowInitOptions(); 
			//options.systemChrome = NativeWindowSystemChrome.STANDARD; 
			//options.transparent = false; 
			//var newWindow:NativeWindow = new NativeWindow(options);
			//
			//newWindow.width = 600; 
			//newWindow.height = 400; 
			 //
			stage.align = StageAlign.TOP_LEFT; 
			stage.scaleMode = StageScaleMode.NO_SCALE; 
		 //
			//activate and show the new window 
			//
			//newWindow.activate();
			//newWindow.stage.nativeWindow.
			//newWindow.
			//addEventListener(Event.ENTER_FRAME, onC);
			
			// WaitBar.getInstance().show(this);
			
			var g:XMLData = XMLData.getInstance();
			g.loadXML();
			g.addEventListener(Event.COMPLETE, onC);
			
        }
		
		private function onErr(e:MySqlErrorEvent=null):void 
		{
			trace("com")
			//(e.target as Connection).disconnect();
		}
		
		private function handleConnected(e:Event):void 
		{ 
			trace("fff")
			 var st:Statement = conn.createStatement();
        
			var token:MySqlToken = st.executeQuery("INSERT INTO img (label,content,containerLabel) VALUES ('ggggggggggggggggggg','gggggggggggggg','gggggggg')");
			token.addEventListener(MySqlEvent.RESULT, onR0);
			token.addEventListener(MySqlEvent.RESPONSE, onR1);
			//token.addEventListener(MySqlEvent.COLUMNDATA, onR1);
			//token.addEventListener(MySqlEvent.PARAMS, onR1);
			//token.addEventListener(MySqlEvent.ROWDATA, onR1);
		}
		
		private function onR0(e:MySqlEvent):void 
		{
			trace("fff")
			 while (e.resultSet.next() ) {    
			  trace(e.resultSet.getString("id")+"-----"+e.rowsAvailable);    
			  //var email = rs.getString(2);    
			 }

		}
		
		private function onR1(e:MySqlEvent):void 
		{
			trace(e.affectedRows)
			trace("fff")
			conn.disconnect();
		}
		
		private function onC(e:Event):void 
		{
			//trace((XMLData.getInstance().pagesData[0] as PageData));
			
			//var s:AbstractItemContainer = new AbstractItemContainer();
			//s.x = 50;
			//s.y = 100;
			//addChild(s);
			//s.fillData(XMLData.getInstance())
			//SqlModel.getInstance().del(XMLData.getInstance().pagesData[0].textContainer[0].container[0], onErr);
			//AddPanel.getInstance().add(XMLData.getInstance().pagesData[0].textContainer[0] as IGroupBtn,XMLData.getInstance().pagesData[0].id,this);
			
			//var hh:ImgData = new ImgData("", "时间到了附近阿斯兰的飞机爱上了京东方拉萨尽快答复", "", "1.jpg", "1.jpg", "1.jpg");
			//addChild(new FileBtn(hh, IcoBitmapdatas.MusicType,true, this, 0, -200));
			//SurePanel.getInstance().show("操作已asfdasdfasdfasdsadf完成",this.stage,onErr);
			
			UserManagerPanel.getInstance().show(this.stage);
		}
        
       
    }
}
